package com.suixinsanren.design.state.demo.demo04;

public class SoldOutState implements State {

    private final GumballMachine gumballMachine;

    public SoldOutState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        System.out.println("糖果已售罄，无法开始游戏，您的硬币已退还");
    }

    @Override
    public void ejectQuarter() {
        System.out.println("糖果已售罄，当前没有硬币投入");
    }

    @Override
    public void turnCrank() {
        System.out.println("糖果已售罄，无法开始游戏");
    }

    @Override
    public void refill(int numberGumball) {
        this.gumballMachine.setCount(this.gumballMachine.getCount() + numberGumball);
        if (this.gumballMachine.getCount() > 0) {
            System.out.println("补充了" + numberGumball + "颗糖果");
            this.gumballMachine.setCurrentState(this.gumballMachine.getNoQuarterState());
        } else {
            this.gumballMachine.setCurrentState(this.gumballMachine.getSoldOutState());
        }
    }

    @Override
    public String toString() {
        return "糖果售罄状态";
    }
}
